package com.zzz;


import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.BufferedReader;
import java.io.InputStreamReader;


/**
 * Merge 抽象Action
 *
 * @author yuhao.wang3
 */
public   class ShowProjectNameAction extends AnAction {


    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        @Nullable Project project = e.getData(PlatformDataKeys.PROJECT);

        try {
            // 创建HttpClient实例
            HttpClient httpClient = HttpClientBuilder.create().build();
            // 创建POST请求
            HttpPost request = new HttpPost("https://hq.sinajs.cn/?_=1710826698468/&list=nf_LC2407,nf_AU2406,nf_AG2406,nf_M2405");
            // 添加请求头
            request.addHeader("Accept", "*/*");
            // 添加请求头
            request.addHeader("Referer", "https://finance.sina.com.cn/futures/quotes/LC2407.shtml");
            // 添加请求体（JSON数据）
            // 发送请求并获取响应
            HttpResponse response = httpClient.execute(request);
            // 读取响应内容
            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String line;
            StringBuilder result = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                result.append(line);
            }

            // 打印响应内容
            System.out.println("Response: " + result.toString());
            int flag2 = Messages.showYesNoCancelDialog(result.toString(),"dfdfd",null);
            System.out.println("flag = " + flag2);
        } catch (Exception ee) {
            ee.printStackTrace();
        }
    }

}
